﻿-- =============================================
-- Author:		zengfei
-- Create date: 09m/09/2011
-- Description:	操作员工资料表
-- =============================================
Create PROCEDURE [dbo].[Usp_ModifyEmployee]
	@p_Action	char,				-- A:新增, C:修改, D:删除
	@p_EmployeeNo	varchar(10),
	@p_ChineseName	varchar(20),
	@p_EnglishName	varchar(30),
	@p_Title	varchar(30),
	@p_Gender	varchar(2),
	@p_Tel	varchar(15),
	@p_Mobile	varchar(15),
	@p_Address	varchar(200),
	@p_ZipCode	varchar(6),
	@p_IDCardNo	varchar(18),
	@p_HireDate	datetime,
	@p_Department	varchar(20),
	@p_LoginID	varchar(20),
	@p_RecordID	int out,
	@p_ErrMsg	varchar(100) out,
	@p_RFlag	smallint out
AS
if	@p_Action = 'A'
begin
	if	exists (select * from Employee where EmployeeNo = @p_EmployeeNo)
	begin
		raiserror('员工编号[%s]重复!', 16, 1, @p_EmployeeNo)
		goto ErrHandle
	end
	
	insert into Employee (EmployeeNo, ChineseName, EnglishName, Title, Gender, Tel, Mobile, [Address], ZipCode, IDCardNo, HireDate, Department, LoginID)
		values (@p_EmployeeNo, @P_ChineseName, @p_EnglishName, @p_Title, @p_Gender, @P_Tel, @P_Mobile, @p_Address,@p_ZipCode, @p_IDCardNo, @p_HireDate, @p_Department, @p_LoginID)
	
	if	@@ERROR <> 0 or @@ROWCOUNT = 0 goto ErrHandle
	
	select @p_RecordID = @@IDENTITY 
end
else if	@p_Action = 'C'
begin
	update Employee set ChineseName = @p_ChineseName, 
						EnglishName = @p_EnglishName, 
						Title = @p_Title, 
						Gender = @p_Gender, 
						Tel = @p_Tel, 
						Mobile = @p_Mobile, 
						[Address] = @p_Address, 
						ZipCode = @p_ZipCode, 
						IDCardNo = @p_IDCardNo,
						HireDate = @p_HireDate, 
						Department = @p_Department, 
						LoginID = @p_LoginID
					where RecordID = @p_RecordID 
	
	if	@@ERROR <> 0 or @@ROWCOUNT = 0 goto ErrHandle
end
else if	@p_Action = 'D'
begin
	Delete from Employee where RecordID = @p_RecordID 
	
	if	@@ERROR <> 0 or @@ROWCOUNT = 0 goto ErrHandle
end

set @p_RFlag = 1

ErrHandle:
set @p_RFlag = -1
